package site.xuqing.androidbase.util;

import android.util.Log;

import site.xuqing.androidbase.cons.Constant;

/**
 * @author xuqing
 * @Description Log帮助类
 * @createTime 2022年01月13日 14:06:52
 */
public class LogUtil {
    /**
     * 打印普通info类消息
     * @param tag TAG
     * @param msg Msg
     */
    public static void log(String tag,String msg){
        Log.i(tag,msg);
    }
    
    /**
     * 打印网络消息
     * @param msg Msg
     */
    public static void logNet(String msg){
        Log.d(Constant.LOG_TAG_HTTP_NET,msg);
    }
    
    /**
     * 打印activity源
     */
    public static void logActivity(String activityName){
        Log.d(Constant.LOG_TAG_ACTIVITY,"("+activityName+".java:1)");
    }
    
    /**
     * 打印fragment源
     */
    public static void logFragment(String fragmentName){
        Log.d(Constant.LOG_TAG_FRAGMENT,"("+fragmentName+".java:1)");
    }
    
    /**
     * 打印当前位置相关信息，可以作为mark使用
     */
    public static void log(){
        Log.d(Constant.LOG_TAG_MARK,getMassage());
    }
    
    private static String getMassage(){
        int index = 4;
        StringBuilder stringBuffer = new StringBuilder();
        try {
            StackTraceElement[] stackTrace = Thread.currentThread().getStackTrace();
            String className = stackTrace[index].getFileName();
            String methodName = stackTrace[index].getMethodName();
            int lineNumber = stackTrace[index].getLineNumber();
            methodName = methodName.substring(0, 1).toUpperCase() + methodName.substring(1);
            stringBuffer.append("[(").append(className).append(":").append(lineNumber).append(")#").append(methodName).append("] ");
        } catch (Exception e) {
            e.printStackTrace();
        }
    
        return stringBuffer.toString();
    }
}
